/**
 * Created by zangyin on 16/6/7.
 */

import React, {Component} from 'react';

import {View, Navigator, Platform, BackAndroid} from 'react-native';

export default class CustomNavigator extends Navigator {
  // 构造
  constructor(props) {
    super(props);
    // 初始状态

    this.subscription = this._getNavigationContext().addListener('didfocus', () => {

      let routers = this.getCurrentRoutes();
      if (routers.length <= 1) {
        this.props.showTabbar();
      }
    });

    this.push = (route) => {
      super.push(route);
      console.log('navigator', this.props);
      if (this.props.hiddenTabbar) {
        this.props.hiddenTabbar();
      }
    }

    this.pop = (route) => {
      super.pop(route);
      const routers = this.getCurrentRoutes();
      // alert(routers.length)
      if (routers.length <= 2) {
        this.props.showTabbar();
      }
    }
  }

  componentWillUnmount() {
    this.subscription.remove();
  }
}
